<?php
class Utilities{
	public function multipleSelected(){
		?>
		<link rel="stylesheet" type="text/css" href="html/multiselect/jquery.multiselect.css" />
		<link rel="stylesheet" type="text/css" href="html/multiselect/style.css" />
		<link rel="stylesheet" type="text/css" href="html/multiselect/prettify.css" />
		<link rel="stylesheet" type="text/css" href="html/multiselect/jquery-ui.css" />
		<!-- <script type="text/javascript" src="html/multiselect/jquery.js"></script> -->
		<script type="text/javascript" src="html/multiselect/jquery-ui.min.js"></script>
		<script type="text/javascript" src="html/multiselect/prettify.js"></script>
		<script type="text/javascript" src="html/multiselect/jquery.multiselect.js"></script>		
		<?php
	}
	public function selectList($selname, $lists,$defaultText = "" ,$defaultValue = "", $valueId, $valueName, $classname = "", $valueSelected = "", $javascript=""){
		$class = ($classname != "") ? "class=".$classname : "";		
		$select = "<select ".$javascript." id=".$selname." name=".$selname." ".$class.">";
		$select .= "<option value=".$defaultValue.">".$defaultText."</optoin>";
		for($i=0;$i<sizeof($lists);$i++){
			$selected = ($valueSelected == $lists[$i]->$valueId) ? "selected='selected'" : "";
			$select .= "<option ".$selected." value=".$lists[$i]->$valueId.">".$lists[$i]->$valueName."</optoin>";
		}
		$select .= "</select>";
		return $select; 
	}
	public function selectListMulti($idname, $selname, $lists, $defaultText = "" ,$defaultValue = "", $valueId, $valueName, $classname = "", $valueSelected = ""){
		$class = ($classname != "") ? "class=".$classname : "";		
		$select = "<select  multiple='multiple' id=".$idname." name=".$selname." ".$class.">";
		if (!empty($defaultValue)){
			$select .= "<option value=".$defaultValue.">".$defaultText."</optoin>";
		}					
		for($i=0;$i<sizeof($lists);$i++){
			$selected = false;
			for ($j=0;$j<count($valueSelected);$j++){
				if ($valueSelected[$j] == $lists[$i]->$valueId){
					$select .= "<option selected='selected' value=".$lists[$i]->$valueId.">".$lists[$i]->$valueName."</optoin>";
					$selected = true;
				}
			}	
			if (!$selected){			
				$select .= "<option ".$selected." value=".$lists[$i]->$valueId.">".$lists[$i]->$valueName."</optoin>";
			}
		}		
		$select .= "</select>";
		return $select; 
	}
	public function renderthumbnail($imagefull){
		
		$path_file = "";
		$image_intro = explode(',', $imagefull);		
		$imges = explode(':',$image_intro[0]);				
		$imagepath = stripslashes(substr($imges[1], 1, strlen($imges[1]) - 2));
		$paths		= explode('/', $imagepath);
		$fname = $paths[sizeof($paths)-1];
		if (sizeof($paths) > 1){
			for ($p=0;$p<sizeof($paths) - 1;$p++){
				$path_file .=$paths[$p]."/";
			}
		}			
		if (!is_dir($path_file.'thumbnail')){
			mkdir($path_file.'thumbnail');
		}
		if (!file_exists($path_file.'thumbnail/'.$fname)){
			Utilities::createThumbs($path_file,$fname, $path_file.'thumbnail/', 80);	
		}
		return $path_file.'thumbnail/'.$fname;
	}	
	public function createThumbs( $pathToImages,$fname, $pathToThumbs, $thumbWidth ) {
		$info = pathinfo($pathToImages . $fname);
//		print_r($info);
//		echo $pathToImages;
		if ( strtolower($info['extension']) == 'jpg' ) 
		{

		  $img = imagecreatefromjpeg( "{$pathToImages}{$fname}" );
		  $width = imagesx( $img );
		  $height = imagesy( $img );
	
		  // calculate thumbnail size
		  $new_width = $thumbWidth;
		  $new_height = floor( $height * ( $thumbWidth / $width ) );
	
		  // create a new tempopary image
		  $tmp_img = imagecreatetruecolor( $new_width, $new_height );
	
		  // copy and resize old image into new image 
		  imagecopyresized( $tmp_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height );
	
		  // save thumbnail into a file
		  imagejpeg( $tmp_img, "{$pathToThumbs}{$fname}" );
		}
	}
	public function tabSubMenu( $classId ){
		?>
        <link rel="stylesheet" href="<?php echo $this->baseurl; ?>/templates/ga/css/tabJquery.css" type="text/css" />
        <div id="tabvanilla" class="widget">
            <ul class="tabnav tabNews">
                <li <?php echo ($classId == 8) ? 'class="ui-tabs-selected"' : ''?>><a class="tabIndex" href="index.php?option=com_news&view=news&catid=8">News</a></li>
                <li><a href="#">Events</a></li>
                <li><a href="#">Gallery</a></li>
                <li <?php echo ($classId == 11 || $classId == 14 || $classId == 15) ? 'class="ui-tabs-selected"' : ''?>><a href="index.php?option=com_news&view=career&catid=11">Career & HR Tips Series</a></li>
            </ul>            
        </div>
        <?php
	}
}
?>